import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

const String VOICE_FEMALE = "F";
const String VOICE_MALE = "M";
const String VOICE_DUYY = "Y";
const String VOICE_DUXY = "X";

class FlutterBaidutts {
  static const MethodChannel _channel = const MethodChannel('flutter_baidutts');

  Future<int> init({
    @required String appId,
    @required String appKey,
    @required String appSecret,
    String voice = VOICE_FEMALE,
  }) {
    return _channel.invokeMethod<int>('init', {
      'appId': appId,
      'appKey': appKey,
      'appSecret': appSecret,
      'voice': voice,
    });
  }

  Future<int> speak(String text) async {
    return _channel.invokeMethod<int>('speak', {
      'text': text,
    });
  }

  Future<int> pause() async {
    return _channel.invokeMethod<int>('pause');
  }

  Future<int> resume() async {
    return _channel.invokeMethod<int>('resume');
  }

  Future<int> stop() async {
    return _channel.invokeMethod<int>('stop');
  }

  Future<int> release() async {
    return _channel.invokeMethod<int>('release');
  }

  factory FlutterBaidutts() => _getInstance();

  static FlutterBaidutts get instance => _getInstance();

  static FlutterBaidutts _instance;

  FlutterBaidutts._internal() {}

  static FlutterBaidutts _getInstance() {
    if (_instance == null) {
      _instance = new FlutterBaidutts._internal();
    }

    return _instance;
  }
}
